home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / NJMOVE.ASM < prev    next >
Assembly Source File  |  1989-01-16  |  46KB  |  2,047 lines

  1.     page    60,150
  2.     title    NJMOVE - Nifty James' MOVE Utility
  3.     subttl    (C) 1989 Blaszczak
  4.  
  5. ;
  6. ; Nifty James' Famous Move Utility
  7. ; Version 1.00 of 16 January 1989
  8. ; (C) Copyright 1989 By Mike Blaszczak
  9. ;
  10.  
  11. ;
  12. ; This file is written for the Microsoft Macro Assembler,
  13. ; Version 5.10 or higher.  The program will not properly
  14. ; operate under any DOS version less than 2.00, but will
  15. ; work with any PC-DOS or MS-DOS Versions 2.00 and above.
  16. ; This is an .EXE file, and should not be run through
  17. ; EXE2BIN.  The executable file should be packed, or the
  18. ; LINK option /EXEPACK should be used.
  19. ;
  20.  
  21.  
  22. ; ----------------------------------------------------------------------------
  23. ;    ASCII Equates
  24.  
  25. eos    equ    000h        ; end-of-string character
  26. bell    equ    007h        ; bell beeper
  27. bs    equ    008h        ; back-space
  28. tab    equ    009h        ; tab
  29. lf    equ    00Ah        ; line-feed character
  30. cr    equ    00Dh        ; carriage return
  31. ctrlz    equ    01Ah        ; control zee (aka, EOF)
  32. eof    equ    ctrlz
  33. space    equ    020h        ; blank space
  34.  
  35.  
  36. ; ----------------------------------------------------------------------------
  37. ;    DOS Function Calls and constants
  38.  
  39. INTDOS    equ    021h
  40.  
  41. STDIN    equ    0        ; standard output file handle
  42. STDOUT    equ    1        ; standard input file handle
  43.  
  44. NormalAttrib    equ    000h        ; normal attribute byte (nothing set)
  45. SubDirAttrib    equ    010h        ; attribute for a directory
  46.  
  47. PutChar    equ    002h        ; put character to stdout
  48. GetChar    equ    007h        ; get char from stdin, with no echo
  49. GetDefDisk    equ    019h        ; get current default disk drive
  50. SetDTA    equ    01Ah        ; set the DOS DTA address
  51. FreeSpace    equ    036h        ; get disk free space
  52. CreateHandle    equ    03Ch        ; create a file handle
  53. OpenHandle    equ    03Dh        ; open a file handle
  54. CloseHandle    equ    03Eh        ; close a file handle
  55. ReadHandle    equ    03Fh        ; read from a file or device
  56. WriteHandle    equ    040h        ; write to a file or device
  57. DeleteFile    equ    041h        ; delete a file name
  58. GetAttrib    equ    04300h        ; get file attributes
  59. SetAttrib    equ    04301h        ; set file attributes
  60. IOCTL    equ    044h        ; I/O control/status call
  61. GetDefDir    equ    047h        ; get current default directory
  62. Terminate    equ    04Ch        ; terminate this program
  63. FindFirst    equ    04Eh        ; find first file matching wildcard
  64. FindNext    equ    04Fh        ; find next file matching wildcard
  65. RenameFile    equ    056h        ; rename a file
  66. GetDateTime    equ    05700h        ; get date or time
  67. SetDateTime    equ    05701h        ; set date or time
  68. NormalizePath    equ    060h        ; normalize pathname
  69. GetPSP    equ    062h        ; get the programs PSP
  70.  
  71. ; note that NormalizePath is an undocumented call.  DS:SI points to a
  72. ; path specification which may contain a drive specifier.  ES:DI points
  73. ; to a buffer for the normalized pathname.  The file simply fixes the
  74. ; "." and ".." references in the file, making the pathname as short as
  75. ; possible.  This expansion is simply used so the user knows *exactly*
  76. ; where the file is coming from.  Microsoft, in their infinite (heh)
  77. ; wisdom (hah) did not document this very useful function call.
  78.  
  79.  
  80. ; ----------------------------------------------------------------------------
  81. ;    ERRORLEVEL values that we return
  82.  
  83. ERR_None    equ    0        ; none!
  84. ERR_Usage    equ    1        ; problem on command line
  85. ERR_NotFound    equ    2        ; file not found
  86. ERR_BadFile    equ    3        ; given a device, or an unparsable
  87. ERR_CopyProblem    equ    4        ; problem while copying
  88. ERR_Renaming    equ    5        ; problem while renaming
  89.  
  90.  
  91. ; These are the data structures used in this program.  The first is used
  92. ; internally to describe the way a file name is broken down into its
  93. ; components.
  94.  
  95. FileDriveLen    equ    3
  96. FilePathLen    equ    65
  97. FileNameLen    equ    9
  98. FileExtLen    equ    5
  99.  
  100. FileNameS    struc
  101. drive    db    FileDriveLen dup(?)    ; drive        B:
  102. path    db        FilePathLen  dup(?)    ; path        \bin\booger
  103. fname    db    FileNameLen  dup(?)    ; filename    njmove
  104. fext    db    FileExtLen   dup(?)    ; extension    asm
  105. FileNameS    ends
  106.  
  107.  
  108. ; This data structure is the one that DOS uses to store the DTA.  When
  109. ; we call FINDFIRST and FINDNEXT, this information will be set up to contain
  110. ; the rest of the file that we are moving.
  111.  
  112. DOSDTAS    struc
  113. _dta_reserved    db    21 dup (?)    ; reserved space
  114. dta_attribute    db    ?        ; attribute byte
  115. dta_time    dw    ?        ; file modification time
  116. dta_date    dw    ?        ; file modification date
  117. dta_size    dd    ?        ; file size (doubleword!)
  118. dta_fname    db    13 dup (?)    ; file name (ASCIIZ)
  119. DOSDTAS    ends
  120.  
  121.  
  122. ; ============================================================================
  123.     .model    small
  124.     .stack    0100h        ; get a *real* stack
  125.  
  126.  
  127. ; ============================================================================
  128. ; Our data area follows.  This data area contains both initialized and
  129. ; uninitialized data.                            
  130.  
  131.     .data
  132.  
  133. Banner    db    "Nifty James' Famous Move Utility",cr,lf
  134.     db    "Version 1.00 of 16 January 1989",cr,lf
  135.     db    "(C)Copyright 1989 by Mike Blaszczak",cr,lf
  136.     db    lf,eos
  137.  
  138. NoSpace    db    "NJMOVE: Destination device ran out of space"
  139. CRLFSet    db    cr,lf,eos
  140.  
  141. NoSelf    db    "NJMOVE: A File can not be moved into itself"
  142.     db    cr,lf,eos
  143.  
  144. CantWrite    db    "NJMOVE: Couldn't write to destination device"
  145.     db    cr,lf,eos
  146.  
  147. CantRead    db    "NJMOVE: Couldn't read from source device"
  148.     db    cr,lf,eos
  149.  
  150. CantSDevice    db    "NJMOVE: Can't move from a device"
  151.     db    cr,lf,eos
  152.  
  153. CantDDevice    db    "NJMOVE: Can't move to a device"
  154.     db    cr,lf,eos
  155.  
  156. BadSource    db    "NJMOVE: Bad Source File Specification"
  157.     db    cr,lf,eos
  158.  
  159. BadDest    db    "NJMOVE: Bad Destination File Specification"
  160.     db    cr,lf,eos
  161.  
  162. CouldntRename    db    "NJMOVE: Could not perform rename operation"
  163.     db    cr,lf,eos
  164.  
  165. NameCollide    db    "NJMOVE: File naming collision; file already exists"
  166.     db    cr,lf,eos
  167.  
  168. CouldntDIR    db    "NJMOVE: Couldn't get default directory of drive "
  169.     db    eos
  170.  
  171. NoMatches    db    "NJMOVE: No files matched ",eos
  172.  
  173. UAborted    db    cr,lf,"NJMOVE: User Aborted",cr,lf,lf,eos
  174.  
  175. Usage    db    "Usage:",cr,lf
  176.     db    tab,"NJMOVE <source> <dest> [/C]",cr,lf
  177.     db    lf
  178.     db    tab,"<source>",tab,"source file name",cr,lf
  179.     db    tab,"<dest>",tab,tab,"destination file name",cr,lf
  180.     db    tab,tab," both file names may "
  181.     db    "contain wildcards",cr,lf
  182.     db    tab,"[/C]",tab,"specifies optional confirmation"
  183.     db    cr,lf,lf,eos
  184.  
  185. MovingMess    db    "Moving ",eos
  186. MoveCMess    db    "Move ",eos
  187.  
  188. CopyingMess    db    "Copying ",eos
  189. CopyCMess    db    "Copy ",eos
  190.  
  191. ToMess    db    " to ",eos
  192.  
  193. BackSlash    db    "\",eos
  194.  
  195. DotStar    db    "."
  196. Star    db    "*",eos
  197.  
  198. ConfirmPrompt    db    "? [No] ",eos
  199.  
  200.  
  201. confirmmode    db    0        ; set if the /C was to be found
  202. copymode    db    0        ; set to one if we must copy
  203.                 ;  from disk to disk instead of
  204.                 ;  just renaming the files
  205.     even
  206.  
  207. sourcespec    dw    0        ; source file specification
  208. destspec    dw    0        ; destination spec
  209.  
  210. sourcewildf    db    0        ; set if sourcef has wildcard name
  211. sourcewilde    db    0        ; set if sourcef has wildcard ext
  212. sourcehase    db    0        ; set if sourcef has extension
  213. sourcef    FileNameS <>        ; source description
  214. sourcefile    db    64 dup (0)    ; total file name
  215.  
  216. destwildf    db    0        ; set if destf has wildcard name
  217. destwilde    db    0        ; set if destf has wildcard ext
  218. desthase    db    0        ; set if destf has extension
  219. destf    FileNameS <>        ; destination description
  220. destfile    db    64 dup (0)    ; total file name
  221.  
  222. mydta    DOSDTAS <>        ; a place for DOS to store its stuff
  223.                 ; during FINDFIRST + FINDNEXT
  224.  
  225. ; These variables are used by the copyfile procedure
  226.  
  227. sourceh    dw    ?        ; handle for source file
  228. desth    dw    ?        ; destination file handle
  229.  
  230. ; ----------------------------------------------------------------------------
  231. ; These areas are all data buffers that are not initialized, generally.
  232.  
  233.     even
  234.  
  235. argvectors    dw    64 dup (0)    ; pointers to each argumnet
  236. argcount    dw    0        ; count of arguments
  237. argbuff    db    128 dup (0)    ; buffer to hold args for DS access
  238.  
  239. CopyBufferLen    equ    16384
  240. copybuffer    db    CopyBufferLen dup (?)
  241.                 ; this buffer is used while copying
  242.  
  243. temppath    db    FilePathLen dup(?)
  244.                 ; area used by check4path and
  245.                 ; normalizepath
  246.  
  247. fixedpath    db    FilePathLen dup(?)
  248.                 ; area used by normalize path, too.
  249.  
  250. ; This area is used by the confirm procedure
  251.  
  252. confirmreply    db    ?
  253.  
  254.  
  255. ; ============================================================================
  256. ; This is the program code.  The execution of the program starts at the
  257. ; very first instruction here.
  258.  
  259.     .code
  260.  
  261.     ; first, put the banner of our program on the screen
  262.  
  263.     mov    ax,@data
  264.     mov    ds,ax
  265.     mov    si,offset Banner
  266.     call    putstr
  267.  
  268.     ; set the DTA to point to ou